<?php
/**
 *    提现审核控制器
 *
 *    @author    censhuixing
 *    @time   2014-05-24
 */
class CashApp extends BackendApp
{
	var $_cash_mod;

	function __construct()
	{
		$this->PartnerApp();
	}

	function PartnerApp()
	{
		parent::BackendApp();

		$this->_cash_mod =& m('usercash');
	}

	/**
     *    管理
     *
     *    @author    censhuixing
     *    @time   2014-05-24
     *    @return    void
     */
	function index()
	{

		$search_options = array(
		'real_name'   => '真实姓名',
		//'bank_name'   => '银行名称',
		'bank_account'   => '银行账号',
		);
		/* 默认搜索的字段是真实姓名 */
		$field = 'real_name';
		array_key_exists($_GET['field'], $search_options) && $field = $_GET['field'];
		$conditions = $this->_get_query_conditions(array(array(
		'field' => $field,       //按真实姓名,银行名称,银行账号进行搜索
		'equal' => 'LIKE',
		'name'  => 'search_name',
		),array(
		'field' => 'outstatus',
		'equal' => '=',
		'type'  => 'numeric',
		),array(
		'field' => 'add_time',
		'name'  => 'add_time_from',
		'equal' => '>=',
		'handler'=> 'gmstr2time',
		),array(
		'field' => 'add_time',
		'name'  => 'add_time_to',
		'equal' => '<=',
		'handler'   => 'gmstr2time_end',
		),array(
		'field' => 'amount',
		'name'  => 'amount_from',
		'equal' => '>=',
		'type'  => 'numeric',
		),array(
		'field' => 'amount',
		'name'  => 'amount_to',
		'equal' => '<=',
		'type'  => 'numeric',
		),
		));

		$page   =   $this->_get_page(10);    //获取分页信息
		//更新排序
		if (isset($_GET['sort']) && isset($_GET['order']))
		{
			$sort  = strtolower(trim($_GET['sort']));
			$order = strtolower(trim($_GET['order']));
			if (!in_array($order,array('asc','desc')))
			{
				$sort  = 'add_time';
				$order = 'desc';
			}
		}
		else
		{
			$sort  = 'add_time';
			$order = 'desc';
		}
		$orders = $this->_cash_mod->find(array(
		'conditions'    => '1=1 ' . $conditions,
		'limit'         => $page['limit'],  //获取当前页的数据
		'order'         => "$sort $order",
		'count'         => true             //允许统计
		));
		include(ROOT_PATH.'/includes/cfg_status.php');
		foreach ($orders as $key=>$val)
		{
			$orders[$key]['pay_bank_name'] = $cfg_bank_name[$val['bank_name']];
			$orders[$key]['outstatus_name'] = $cfg_cash_status[$val['outstatus']];
		}
		$page['item_count'] = $this->_cash_mod->getCount();   //获取统计的数据
		$this->_format_page($page);
		$this->assign('filtered', $conditions? 1 : 0); //是否有查询条件

		$this->assign('order_status_list', $cfg_cash_status);//到账状态
		$this->assign('search_options', $search_options);
		$this->assign('page_info', $page);          //将分页信息传递给视图，用于形成分页条
		$this->assign('orders', $orders);
		$this->import_resource(array('script' => 'inline_edit.js,jquery.ui/jquery.ui.js,jquery.ui/i18n/' . i18n_code() . '.js',
		'style'=> 'jquery.ui/themes/ui-lightness/jquery.ui.css'));
		$this->display('cash.index.html');

	}

	/**
     *    编辑
     *    @author    censhuixing
     *    @time   2014-05-24
     */
	function edit()
	{
		$cash_id = isset($_GET['id']) ? intval($_GET['id']) : 0;
		if (!$cash_id)
		{
			$this->show_warning('没有记录');

			return;
		}
		
			include(ROOT_PATH.'/includes/cfg_status.php');
		if (!IS_POST)
		{
			$find_data     = $this->_cash_mod->find($cash_id);
			if (empty($find_data))
			{
				$this->show_warning('没有记录');

				return;
			}
			$cash_info    =   current($find_data);

		

			$cash_info['pay_bank_name']    =   $cfg_bank_name[$cash_info['bank_name']];
			//会员账号
			$_user_mod =& m('member');
			$user_info   =   $_user_mod->get("user_id={$cash_info['user_id']}");
			$cash_info['user_name'] = $user_info['user_name'];


			$this->assign('cash', $cash_info);
			$this->import_resource('jquery.plugins/jquery.validate.js');
			$this->display('cash.form.html');
		}
		else
		{
			$data = array();
			$data['outstatus']      =   intval($_POST['outstatus']);
			$data['admin']       =  $_SESSION['admin_info']['user_name'];
			$data['admin_note'] =   html_script($_POST['admin_note']);//操作备注

			$rows = $this->_cash_mod->edit($cash_id, $data);
			if ($this->_cash_mod->has_error())    //有错误
			{
				$this->show_warning($this->_cash_mod->get_error());

				return;
			}

			$this->admin_log('审核提现申请ID-'.$cash_id.':'.$cfg_cash_status[$data['outstatus']]);

			$this->show_message('审核成功',
			'back_list',     'index.php?app=cash',
			'重新审核', 'index.php?app=cash&amp;act=edit&amp;id=' . $cash_id);
		}
	}


}

?>